package com.orm.analysis.dao;

import com.orm.analysis.model.CustOrder;
import com.orm.analysis.model.Customer;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/10/13
 * Time: 2:49 PM
 * To change this template use File | Settings | File Templates.
 */
public class OrderDAO  extends  GenericJPADAO<CustOrder, Integer> {

       public List<CustOrder> list(int page, int size) {
           Query query = this.em.createQuery("from CustOrder");
           query.setFirstResult((page - 1) * size);
           query.setMaxResults(size);
           return query.getResultList();
       }


       public CustOrder getById(Integer id) {
             return this.em.find(CustOrder.class,id);
       }

       @Transactional
       @Override
       public void save(CustOrder entity) {
            getEntityManager().persist(entity);
       }

}